<?php

// $Id$
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/**
 * Function used to display an horizontal menu inside the admin panel
 *
 * Enable webmasters to navigate thru the module's features.
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
 *
 * @package News
 * @author - stolen to the Newbb team ;-)
 * @copyright	(c) The Xoops Project - www.xoops.org
*/

include '../xoops_version.php';

function adminmenu($currentoption = 0, $breadcrumb = '')
{
global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
$myts =& MyTextSanitizer::getInstance();
	
	/* Nice buttons styles */
	echo "
    	<style type='text/css'>
    	#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 0px solid black; border-right: 0px solid black; margin: 0; }
    	#buttonbar { float:left; width:100%; background: #e7e7e7 url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/bg.png') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 0px solid black; border-right: 0px solid black; margin-bottom: 0px; }
    	#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }
		#buttonbar li { display:inline; margin:0; padding:0; }
		#buttonbar a { float:left; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/left_both.png') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }
		#buttonbar a span { float:left; display:block; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/right_both.png') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }
		/* Commented Backslash Hack hides rule from IE5-Mac \*/
		#buttonbar a span {float:none;}
		/* End IE5-Mac hack */
		#buttonbar a:hover span { color:#333; }
		#buttonbar #current a { background-position:0 -150px; border-width:0; }
		#buttonbar #current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }
		#buttonbar a:hover { background-position:0% -150px; }
		#buttonbar a:hover span { background-position:100% -150px; }
		</style>";

	$tblColors = array();
	$tblColors = array_pad ($tblColors, count($adminmenu), ""); 
	
	if($currentoption>=0) {
		$tblColors[$currentoption] = 'current';
	}
	echo "<div id='buttontop' style='border-right: 1px solid black;border-left: 1px solid black;margin-bottom:8px;padding-bottom:0;'>"; 
	echo "<table style='width: 100%; padding:0;' cellspacing='0'><tr>";
	echo "<td style=\"width: 60%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\">"; if(isset($modversion['config'])){echo"<a class=\"nobutton\" href=\"../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=".$xoopsModule->getVar('mid')."\">Preferences</a> | ";} echo"<a href=\"../index.php\">Go to module</a>"; if(isset($modversion['help'])){echo"| <a href=\"".$modversion['help']."\">Help</a>";} echo "</td>";
	echo "<td style=\"width: 40%; font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;\"><b>" . $xoopsModule->name() . "  </b> " . $breadcrumb . "</td>";
	echo "</tr></table>";
	echo "<div id='buttonbar'>";
	echo "<ul>";
	for($i=0; $i<count($adminmenu); ++$i){ //XOOPS_ROOT_PATH."/modules/".$modversion['dirname']."/admin/
		echo "<li id='" . $tblColors[$i] . "'><a href='".XOOPS_URL."/modules/".$modversion['dirname']."/".$adminmenu[$i]['link']."'><span>" . $adminmenu[$i]['title'] . "</span></a></li>\n";
	}
	echo "</ul></div>";
	echo "</div><div style='margin-bottom:2px;'>&nbsp;</div>";
	
}


function news_collapsableBar($tablename = '', $iconname = '')
{

    ?>
	<script type="text/javascript"><!--
	function goto_URL(object)
	{
		window.location.href = object.options[object.selectedIndex].value;
	}

	function toggle(id)
	{
		if (document.getElementById) { obj = document.getElementById(id); }
		if (document.all) { obj = document.all[id]; }
		if (document.layers) { obj = document.layers[id]; }
		if (obj) {
			if (obj.style.display == "none") {
				obj.style.display = "";
			} else {
				obj.style.display = "none";
			}
		}
		return false;
	}

	var iconClose = new Image();
	iconClose.src = '../images/close12.gif';
	var iconOpen = new Image();
	iconOpen.src = '../images/open12.gif';

	function toggleIcon ( iconName )
	{
		if ( document.images[iconName].src == window.iconOpen.src ) {
			document.images[iconName].src = window.iconClose.src;
		} else if ( document.images[iconName].src == window.iconClose.src ) {
			document.images[iconName].src = window.iconOpen.src;
		}
		return;
	}

	//-->
	</script>
	<?php
	echo "<h4 style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href='#' onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
}


//##############################
//DISPLAY CONFIGURATION SECTION
//##############################
function config(){
global $xoopsDB, $xoopsConfig, $xoopsModule;
include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$form = new XoopsThemeForm('Configuration', 'config', '../admin/admin_formaction.php', 'POST');

//Start Time
$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_configuration")."" ) ;
	if ( $result ) {
		$myrow = $xoopsDB->fetchArray($result);
	}
	
	
	 $select = new XoopsFormSelect('Start Time of Schedule', 'start_time', $myrow['start_time'], $size=1, $multiple=false);
	 	
	
	for ($i = 0; $i < 24; $i++) {
	
	if(date("g:i:s a",$myrow['start_time']) == date("g:i:s a",mktime($i,0,0,0,0,0))){
		$select->addOption(mktime($i,0,0,0,0,0),date("g:i:s a",mktime($i,0,0,0,0,0)));
	}else{
		$select->addOption(mktime($i,0,0,0,0,0),date("g:i:s a",mktime($i,0,0,0,0,0)));
	}
	
	if(date("g:i:s a",$myrow['start_time']) == date("g:i:s a",mktime($i,30,0,0,0,0))){
		$select->addOption(mktime($i,30,0,0,0,0),date("g:i:s a",mktime($i,30,0,0,0,0)));
	}else{
		$select->addOption(mktime($i,30,0,0,0,0),date("g:i:s a",mktime($i,30,0,0,0,0)));
	} 

}	

	 $form->addElement($select, false);	
	



//DEFAULT VIEW
	 $select = new XoopsFormSelect('Default View', 'view', $myrow['view'], $size=1, $multiple=false);
     $select->addOption('week','Weekly View');
     $select->addOption('day','Daily View');
	 $form->addElement($select, false);	



//DAILY VIEW CONFIG
	 $select = new XoopsFormSelect('Show Currently Playing Program First In Daily View ', 'current', $myrow['DailyViewCurrent'], $size=1, $multiple=false);
     $select->addOption('true','true');
     $select->addOption('false','false');
	 $form->addElement($select, false);	
	 
	 
	 
	 
	 
//ANNOUNCEMENTS
	$form->addElement(new XoopsFormDhtmlTextArea('Program Schedule Announcements', 'announcements',$myrow['announcements'], 5, 35), $required = false);


//NOW PLAYING IMAGE
	 $select = new XoopsFormSelect('Show program image in block?', 'Show_NP_Image', $myrow['Show_NP_Image'], $size=1, $multiple=false);
     $select->addOption('true','true');
     $select->addOption('false','false');
	 $form->addElement($select, false);		
	
	
	//NOW PLAYING BLOCK DESCRIPTION
	 $select = new XoopsFormSelect('Show description in block?', 'Show_NP_Description', $myrow['Show_NP_Description'], $size=1, $multiple=false);
     $select->addOption('true','true');
     $select->addOption('false','false');
	 $form->addElement($select, false);			
	
	
	//CALL LETTERS
	$form->addElement(new XoopsFormText('Station Call Letters','letters', 4, 4, $myrow['letters']));	
	
	
		 
	
			$form->addElement(new XoopsFormHidden('action', 'configuration'));
			$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
			$form->display();
				
}



//##############################
//DISPLAY CATEGORIES SECTION
//##############################
function categories(){
global $xoopsDB, $xoopsConfig, $xoopsModule;
include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
echo"<SCRIPT LANGUAGE='Javascript' SRC='../include/ColorPicker2.js'></SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>
var cp = new ColorPicker('window'); // Popup window
var cp2 = new ColorPicker(); // DIV style
</SCRIPT>";

$form = new XoopsThemeForm('Add Program Category', 'config', '../admin/admin_formaction.php', 'POST');
$form->addElement(new XoopsFormText("Category Description",'description','50', '100', ''),$required = true);
$form->addElement(new XoopsFormText("Color Code: <A HREF=\"#\" onClick=\"cp.select(document.config.color,'pick');return false;\" NAME=\"pick\" ID=\"pick\">PICK</A>",'color','50', '100', ''),$required = true);

$form->addElement(new XoopsFormButton('', 'update', 'Add Category', 'submit'));
$form->addElement(new XoopsFormHidden('action', 'add_category'));
$form->display();


$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_categories")."" ) ;

echo "<table width='100%' class='outer' cellspacing='1'><tr><th colspan='3'>Current Program Categories & Color Codes</th></tr>
<tr valign='top' align='left' class='head'><td >Category</td><td >Color Code</td><td>Action</td></tr>
";

	if ( $result ) {
		$x=0;
		function oddEven($digit){
			if($digit & 1){
				return "odd";
			}else{
				return "even";
			}
		}
		while ( $myrow = $xoopsDB->fetchArray($result) ) {
			echo "<tr valign='top' align='left'><td class='".oddEven($x)."' width='150'>".stripslashes($myrow['description']).":</td><td bgcolor=\"#".$myrow['color']."\">".$myrow['color']."</td><td class='".oddEven($x)."'><a href='index.php?op=editCategories&amp;currentID=1&amp;ID=".$myrow['ID']."'>Edit</a> - <a href='index.php?op=deleteCategories&amp;currentID=1&amp;ID=".$myrow['ID']."&amp;name=".stripslashes($myrow['description'])."'>Delete</a></td></tr>";
		++$x;
		}
	}

echo "</table>";
}


//##############################
//EDIT CATEGORIES SECTION
//##############################
function editCategories(){
	global $xoopsDB, $xoopsConfig, $xoopsModule;
	echo"<SCRIPT LANGUAGE='Javascript' SRC='../include/ColorPicker2.js'></SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>
var cp = new ColorPicker('window'); // Popup window
var cp2 = new ColorPicker(); // DIV style
</SCRIPT>";
	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_categories")." WHERE ID = '".$_GET['ID']."'" ) ;
	$myrow = $xoopsDB->fetchArray($result);
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Edit Program Category', 'config', '../admin/admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormText("Category Description",'description','50', '100', $myrow['description']),$required = true);
	$form->addElement(new XoopsFormText("Color Code: <A HREF=\"#\" onClick=\"cp.select(document.config.color,'pick');return false;\" NAME=\"pick\" ID=\"pick\">PICK</A>",'color','50', '100', $myrow['color']),$required = true);
	
	$form->addElement(new XoopsFormButton('', 'update', 'Update Category', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'edit_category'));
	$form->addElement(new XoopsFormHidden('ID', $_GET['ID']));
	$form->display();}



//##############################
//DELETE CATEGORIES SECTION
//##############################
function deleteCategories(){
	    global $xoopsDB, $xoopsConfig, $xoopsModule;
		xoops_confirm(array('action'=>'delete_category', 'ID'=>$_GET['ID'],'name'=>$_GET['name']), 'admin_formaction.php', "Are you sure you want to delete this category: ".$_GET['name']."?");
}

//##############################
//ADD PROGRAM SECTION
//##############################
function addProgram(){
  global $xoopsDB, $xoopsConfig, $xoopsModule;

echo"<form name='config' id='config' action='../admin/admin_formaction.php' method='POST' enctype='multipart/form-data'>
<table width='100%' class='outer' cellspacing='1'><tr><th colspan='2'>Add Program</th></tr><tr valign='top' align='left'><td class='head'>Program Title:</td><td class='even'><input type='text' name='title' id='title' size='50' maxlength='100' value='' /></td></tr><tr valign='top' align='left'><td class='head'>Category:</td><td class='even'><select  size='1' name='category' id='category'>";

$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_categories")."" ) ;
		if ( $result ) {
			//$x=0;
			while ( $myrow = $xoopsDB->fetchArray($result) ) {
			echo "<option value='".$myrow['ID']."'>".$myrow['description']."</option>";
			//++$i;
			}
		}


echo"</select></td></tr><tr valign='top' align='left'><td class='head'>Description:</td><td class='even'><textarea name='description' id='description' rows='5' cols='50'></textarea></td></tr><tr valign='top' align='left'><td class='head'>Start Time:</td><td class='even'>
<select  size='1' name='start_time' id='start_time'>";

for($q=0;$q<24; $q++){
echo "<option value='".mktime($q,0,0,0,0,0)."'>".date("h:i:s a", mktime($q,0,0,0,0,0))."</option>";
echo "<option value='".mktime($q,30,0,0,0,0)."'>".date("h:i:s a", mktime($q,30,0,0,0,0))."</option>";
}
echo"</select>

</td></tr><tr valign='top' align='left'><td class='head'>End Time:</td><td class='even'>
<select  size='1' name='end_time' id='end_time'>
<option value='92133000'>12:30:00 am</option>";

for($q=1;$q<24; $q++){
echo "<option value='".mktime($q,0,0,0,0,0)."'>".date("h:i:s a", mktime($q,0,0,0,0,0))."</option>";
echo "<option value='".mktime($q,30,0,0,0,0)."'>".date("h:i:s a", mktime($q,30,0,0,0,0))."</option>";
}

echo"<option value='92217600'>12:00:00 am</option>
</select></td></tr><tr valign='top' align='left'><td class='head'>Web Site URL:</td><td class='even'><input type='text' name='link' id='link' size='50' maxlength='100' value='http://' /></td></tr><tr valign='top' align='left'><td class='head'>Program Image: (150px x 150px, 15k or less)</td><td class='even'><input type='hidden' name='MAX_FILE_SIZE' value='15000' /><input type='file' name='uploadimage' id='uploadimage' /><input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='uploadimage' /></td></tr><tr valign='top' align='left'><td class='head'>Program Host/DJ:</td><td class='even'><input type='text' name='DJ' id='DJ' size='50' maxlength='100' value='' /></td></tr><tr valign='top' align='left'><td class='head'>Program Days:</td>

<td class='even'>
<input type='checkbox' name='mon' value='true' />Monday
<input type='checkbox' name='tue' value='true' />Tuesday
<input type='checkbox' name='wed' value='true' />Wednesday

<input type='checkbox' name='thu' value='true' />Thursday
<input type='checkbox' name='fri' value='true' />Friday
<input type='checkbox' name='sat' value='true' />Saturday
<input type='checkbox' name='sun' value='true' />Sunday
</td></tr><input type='hidden' name='action' id='action' value='add_program' /><tr valign='top' align='left'><td class='head'></td><td class='even'><input type='button' class='formButton' name='update'  id='update' value='Add Program' onClick='formCheck()'/></td></tr></table></form>

<!-- Start Form Vaidation JavaScript //-->
<script type='text/javascript'>
<!--//
function formCheck() {

	if (document.config.title.value == \"\" ) { 
		//window.alert(\"Please enter Program Title:\"); document.config.title.focus(); return false; 
	}else{
		document.config.submit();
	}
}
//--></script>
<!-- End Form Vaidation JavaScript //-->";
		
}


//##############################
//MANAGE PROGRAM SECTION
//##############################
function managePrograms(){
  global $xoopsDB, $xoopsConfig, $xoopsModule;
	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_programs")." ORDER BY start_time asc,mon DESC,tue DESC,wed DESC,thu DESC,fri DESC,sat DESC,sun DESC" ) ;
	 
	 $categories = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_categories")."" ) ;
	 $catData = array();
	 		while ( $mycat = $xoopsDB->fetchArray($categories) ) {
				$catData[] = $mycat;
			//++$i;
			}
			
			
	function findCategory($ID){
	global $catData;
		for ($i = 0; $i < count($catData); $i++) {
			if(array_search ($ID, $catData[$i])){
				return $catData[$i]['description'];
				break;
			}
		}
		
	}		

	echo"<form action=\"index.php\" method=\"get\" enctype=\"application/x-www-form-urlencoded\" name=\"editProg\" target=\"_self\">";
	echo "<table width='100%' class='outer' cellspacing='1'><tr><th colspan='10'>Edit Programs</th></tr>";
	echo "<tr valign='top' align='left' class='head' ><td class='head' >Title</td>  <td class='head'>Start Time</td> <td class='head'>End Time</td> <td class='head' >Image</td><td>Days</td> <td>Action</td></tr>";
		if ( $result ) {
			$x=0;

			
			while ( $myrow = $xoopsDB->fetchArray($result) ) {
			if($x&1){
				$style = 'odd';
			}else{
				$style = 'even';
			}
			
				$displayDays = "";
				$weekDays = array('mon','tue','wed','thu','fri','sat','sun');
				for ($i = 0; $i < 7; $i++) {
					if($myrow[$weekDays[$i]] == 'true'){
						$displayDays = $displayDays . "&#8226;".$weekDays[$i]."<br>";
					}
				}
			
			
				echo "<tr valign='top' align='left' class='$style'><td>".stripslashes ( $myrow['title'])."</td> <td  nowrap>".date("g:i:s a",$myrow['start_time'])."</td> <td  nowrap>".date("g:i:s a",$myrow['end_time'])."</td> <td><img src='../images/uploads/".$myrow['image']."'></td><td nowrap>".$displayDays."</td> <td><a href='index.php?op=editProgram&amp;currentID=3&amp;ID=".$myrow['ID']."'>Edit</a> - <a href='index.php?op=deleteProgram&amp;currentID=3&amp;ID=".$myrow['ID']."&amp;name=".stripslashes($myrow['title'])."'>Delete</a></td></tr>";
			++$i;
			++$x;
			}
		}
	
	echo "</table></form>"; 
		
}


//##############################
//EDIT PROGRAM SECTION
//##############################
function editProgram(){
  global $xoopsDB, $xoopsConfig, $xoopsModule;
	 $result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_programs")." WHERE ID = '".$_GET['ID']."'" ) ;
	 if ( $result ) {
	 	$myrow = $xoopsDB->fetchArray($result);
	 }
	 



echo"

<form name='config' id='config' action='../admin/admin_formaction.php' method='POST' enctype='multipart/form-data'>

<table width='100%' class='outer' cellspacing='1'>
<tr><th colspan='2'>Edit Programs</th></tr>
<tr valign='top' align='left'>
	<td class='head'>Program Title:</td>
	<td class='even'><input type='text' name='title' id='title' size='50' maxlength='100' value='".stripslashes ( $myrow['title'])."' /></td>
</tr>

<tr valign='top' align='left'>
	<td class='head'>Category:</td>
	<td class='even'><select name=\"category\" size=\"1\">";
	$categories = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("program_schedule_categories")."" ) ;
	 $catData = array();
	 		while ( $mycat = $xoopsDB->fetchArray($categories) ) {
				$catData[] = $mycat;
			//++$i;
			}
			
			

		for ($i = 0; $i < count($catData); $i++) {
			if(array_search ($myrow['category'], $catData[$i])){
				echo "<option value='".$catData[$i]['ID']."' selected>".stripslashes ( $catData[$i]['description'])."</option>\n";
			}else{
				echo "<option value='".$catData[$i]['ID']."'>".stripslashes ( $catData[$i]['description'])."</option>\n";
			}
		}
		
	
	
	
	
	
	echo"</select></td>
</tr>";


echo"<tr valign='top' align='left'>
	<td class='head'>Description:</td>
	<td class='even'><textarea name='description' id='description' rows='5' cols='50'>".stripslashes ( $myrow['description'])."</textarea></td>
</tr>

<tr valign='top' align='left'>
	<td class='head'>Start Time: ".date("g:i:s a",$myrow['start_time'])."</td>
	<td class='even'>
<select  size='1' name='start_time' id='start_time'>";

for ($i = 0; $i < 24; $i++) {
	
	if(date("g:i:s a",$myrow['start_time']) == date("g:i:s a",mktime($i,0,0,0,0,0))){
		echo "<option value='".mktime($i,0,0,0,0,0)."' selected>".date("g:i:s a",mktime($i,0,0,0,0,0))."</option>\n";
	}else{
		echo "<option value='".mktime($i,0,0,0,0,0)."'>".date("g:i:s a",mktime($i,0,0,0,0,0))."</option>\n";
	}
	
	if(date("g:i:s a",$myrow['start_time']) == date("g:i:s a",mktime($i,30,0,0,0,0))){
		echo "<option value='".mktime($i,30,0,0,0,0)."' selected>".date("g:i:s a",mktime($i,30,0,0,0,0))."</option>\n";
	}else{
		echo "<option value='".mktime($i,30,0,0,0,0)."'>".date("g:i:s a",mktime($i,30,0,0,0,0))."</option>\n";
	}

}
echo"
</select>
</td>
</tr>


<tr valign='top' align='left'>
<td class='head'>End Time: ".date("g:i:s a",$myrow['end_time'])."</td>
<td class='even'>
<select  size='1' name='end_time' id='end_time'>";

for ($i = 0; $i < 25; $i++) {
	
	if(date("g:i:s a",$myrow['end_time']) == date("g:i:s a",mktime($i,0,0,0,0,0))){
		echo "<option value='".mktime($i,0,0,0,0,0)."' selected>".date("g:i:s a",mktime($i,0,0,0,0,0))."</option>\n";
	}else{
		echo "<option value='".mktime($i,0,0,0,0,0)."'>".date("g:i:s a",mktime($i,0,0,0,0,0))."</option>\n";
	}
	
	if($i != 24){//don't add an end time of 12:30am
		if(date("g:i:s a",$myrow['end_time']) == date("g:i:s a",mktime($i,30,0,0,0,0))){
			echo "<option value='".mktime($i,30,0,0,0,0)."' selected>".date("g:i:s a",mktime($i,30,0,0,0,0))."</option>\n";
		}else{
			echo "<option value='".mktime($i,30,0,0,0,0)."'>".date("g:i:s a",mktime($i,30,0,0,0,0))."</option>\n";
		}
	}
 
}
echo"
</select></td>
</tr>

<tr valign='top' align='left'>
<td class='head'>Web Site URL:</td>
<td class='even'>
<input type='text' name='link' id='link' size='50' maxlength='100' value='".$myrow['link']."' />
</td>
</tr>

<tr valign='top' align='left'>
<td class='head'>Program Image: (150px x 150px, 15k or less)</td>
<td class='even'><input type='hidden' name='MAX_FILE_SIZE' value='15000' />
<input type='file' name='uploadimage' id='uploadimage' />
<input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='uploadimage' />
</td></tr>

<tr valign='top' align='left'>
<td class='head'>Program Host/DJ:</td>
<td class='even'><input type='text' name='DJ' id='DJ' size='50' maxlength='100' value='".$myrow['DJ']."' /></td>
</tr>

<tr valign='top' align='left'>
<td class='head'>Program Days:</td>
<td class='even'>";
if($myrow['mon'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='mon' checked />Monday";
}else{
	echo"<input type='checkbox' name='days[]' value='mon' />Monday";
}

if($myrow['tue'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='tue' checked />Tuesday";
}else{
	echo"<input type='checkbox' name='days[]' value='tue' />Tuesday";
}

if($myrow['wed'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='wed' checked />Wednesday";
}else{
	echo"<input type='checkbox' name='days[]' value='wed' />Wednesday";
}

if($myrow['thu'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='thu' checked />Thursday";
}else{
	echo"<input type='checkbox' name='days[]' value='thu' />Thursday";
}

if($myrow['fri'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='fri' checked />Friday";
}else{
	echo"<input type='checkbox' name='days[]' value='fri' />Friday";
}

if($myrow['sat'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='sat' checked />Saturday";
}else{
	echo"<input type='checkbox' name='days[]' value='sat' />Saturday";
}

if($myrow['sun'] == 'true'){
	echo"<input type='checkbox' name='days[]' value='sun' checked />Sunday";
}else{
	echo"<input type='checkbox' name='days[]' value='sun' />Sunday";
}



echo"
</td></tr>
<input type='hidden' name='action' id='action' value='edit_program' /><input type='hidden' name='update-ID' id='update-ID' value='".$myrow['ID']."' />
<tr valign='top' align='left'><td class='head'></td><td class='even'>
<input type='button' class='formButton' name='update'  id='update' value='Update Program' onClick='formCheck()'/> &nbsp; &nbsp; <input type='reset' class='formButton' name='reset'  id='reset' value='Reset' /></td></tr>
</table></form>


<!-- Start Form Vaidation JavaScript //--> 
<script type='text/javascript'>
<!--//
function formCheck() {

	if ( document.config.title.value == \"\" ) { 
		window.alert(\"Please enter Program Title:\"); document.config.title.focus(); 
	}else if(confirm(\"Please make a new entry for non consecutive days as this will potentially cause problems in the weekly view of the program schedule.\")){
		document.config.submit();
	}
	
	
}
//--></script>

<!-- End Form Vaidation JavaScript //-->";  
}


//##############################
//DELETE PROGRAM SECTION
//##############################
function deleteProgram(){
 global $xoopsDB, $xoopsConfig, $xoopsModule;
 xoops_confirm(array('action'=>'delete_program', 'ID'=>$_GET['ID'],'name'=>$_GET['name']), 'admin_formaction.php', "Are you sure you want to delete this program: ".$_GET['name']."?");
  
}


//##############################
//DELETE PROGRAM SECTION
//##############################
function help(){
echo "<LINK href=\"../program_schedule.css\" rel=\"stylesheet\" type=\"text/css\">\n";
?>

<table width="100%" >
	<tr><th class='sectionHeader' colspan="2"> Post Installation:</th></tr>
	<tr> <td class='even' valign="top">1) </td> <td class='odd' valign="top">After successfully installing this module, you will need to set the permissions to 777 for the images uploads directory:<br /> <b>chmod 777 program_schedule/images/uploads. </b></td> </tr>
	<tr> <td class='even' valign="top">2) </td> <td class='odd' valign="top">You will also need to set access rights to the Program Schedule Module and to the "Now Playing" block.  You will also need to turn on the visibility of the "Now Playing" block and set it to dsiplay on the front page of the web site as that is it's intended location.</td> </tr>
</table>


<table width="100%">

	<tr><th class='sectionHeader' colspan="2">Getting Started:</th></tr>
	<tr> <td class='even' valign="top">&nbsp;</td> <td class='odd' valign="top">
	Before you begin adding programs to the Program Schedule and building your grid, take a few minutes to decide how you want the program schedule to display. In the configuration section, you can adjust several settings depending on your station's specific needs as described below.</td> </tr>
	
	<tr> <td class='even' valign="top">1)</td> <td class='odd' valign="top">
	<b>Configuration >> Start Time of Schedule</b>
	<p><b>What is the Start Time of Schedule?</b><br>
	Establishing the Start Time of the Schedule allows you to choose a start time for the Weekly View. This view is what visitors to your Web site will see when they click <b>Program Schedule</b> from your home page. Note: All programs that start before the time you set will NOT be displayed in the Weekly View of the Program Schedule.</p>
	<p><b>How do I set the Start Time of Schedule?</b><br>
	To set or change the Start Time of your Weekly View, choose a time from the drop-down list on the right side of your screen. Once you've selected the start time, click Update.</p>
	
	</td> </tr>
	
	<tr> <td class='even' valign="top">2)</td> <td class='odd' valign="top">
	<b>Configuration >> Default View</b>
	<p><b>What is the Default View?</b><br />
	The Default View setting lets you choose which view, either weekly or daily, the visitors to your site will see first. You can present the programming schedule to users in a weekly view or a daily view. <b>Note:</b> Users have the option to change the view when they visit the Web site regardless of what you select as the Default View.</p>
	<p><b>How do I set the Default View?</b><br />
	To set or change the Default View, choose a weekly or daily view from the drop-down list on the right side of your screen. After making your selection, click Update.</p>
	</td> </tr>

	
	<tr> <td class='even' valign="top">3)</td> <td class='odd' valign="top">
	<b>Configuration >> Daily View Configuration</b>
	<p><b>What is the Daily View Configuration?</b><br />
	The Daily View Configuration allows you to further specify what users will see when they look at program information on your Web site. In the Daily View Configuration, you can have the Web page display either the currently playing program (as determined by its start time) or all the programs for a given day starting with the first program of that day.</p>
	<p><b>How do I set the Daily View Configuration?</b><br />
	In the drop-down list on the right side of your screen, you can choose from a "true" and "false" setting. If you select "true", the currently playing program will be listed at the top of the Program Guide page. If you select "false," the Daily View will show all programs for the given day starting with the first program of the day.</p>
	</td> </tr>
	
	
	<tr> <td class='even' valign="top">4)</td> <td class='odd' valign="top">
	<b>Configuration >> Program Schedule Announcements</b>
	<p><b>What is the Program Schedule Announcements section?</b><br />
	The Program Schedule Announcements section allows you to post a notice on the Program Schedule page regarding upcoming program changes, temporary, or special program events. </p>
	<p><b>How do I create an announcement?</b><br />
	To create an announcement, type your message in the small text field and select your font, size, and color from the drop-down lists and then click the <b>Add Button</b> and your announcement will appear in the large text area with its formatting codes. The options above the font selector allow you to insert URLs, e-mail addresses, images, html codes, and quoted text. Once you have created an announcement, click Update. Your message will appear at the top of the Program Schedule page where the end user will see it.</p>
	<p><b>How do I delete an announcement?</b><br />
	In order to remove the notice after you have posted it, delete all the text in the text area and then click Update.</p>
	</td> </tr>

	<tr> <td class='even' valign="top">5)</td> <td class='odd' valign="top">
	<b>Configuration >> Now Playing Block</b>
	<p><b>What is the Now Playing Block Configuration?</b><br />
	This feature allows you to include a program image with the program display in the "Now Playing" block on the Web site's home page. This feature allows visitors to quickly see what is currently playing.</p>
	<p><b>How do I include an image in the Now Playing Block?</b><br />
	In the drop-down list on the right side of your screen, you can choose from a "true" and "false" setting. If you select "true," and the currently playing program has an image associated with it, it will be displayed in the "Now Playing" block. If you do not have an image associated with a program, or if space constraints prevent the display of an image, you can select "false." </p>
	</td> </tr>
			
</table>


<table width="100%">

	<tr><th class='sectionHeader' colspan="2">Program Categories Explained:</th></tr>
	<tr> <td class='even' valign="top">&nbsp;</td> <td class='odd' valign="top">
	The Program Categories section allows you to assign, change, or delete color codes according to the type of program you are entering into the system.  This will help you visually distinguish the different types of content your stations programming consist of.  The default categories are "News & Information", "Music", and "Entertainment" and should be enough for most stations.  There is room in the end users program legend for one additional category without causing the categories to wrap around to another line.
	</td> </tr>
	
	<tr> <td class='even' valign="top">1)</td> <td class='odd' valign="top">
	<b>Program Categories >> Add Categories</b>
	<p>Here you can add a new program category.  You will need to give the category a one or two word description and then pick a color code for it.  If you click on the "PICK" link on the Color Code line, a pop-up window will open from which you can select a color code from.  It is important to choose colors that will work with your web sites' color theme.</p>
	</td> </tr>
	
	<tr> <td class='even' valign="top">2)</td> <td class='odd' valign="top">
	<b>Program Categories >> Edit Categories</b>
	<p>The "Edit Categories" section will allow you to change the descriptions or color codes of existing Program Categories.  Whatever color code changes you make here will alter the background color of all programs asigned to that category.</p>
	</td> </tr>

	
	<tr> <td class='even' valign="top">3)</td> <td class='odd' valign="top">
	<b>Program Categories >> Delete Categories</b>
	<p>Here you can delete existing Program Categories.  All programs asigned to a deleted Program Category will no longer display a unique background color.  Further more, those programs will each have to be manually edited in order to assign a new Category to it.</p>
	</td> </tr>

			
</table>


<table width="100%">

	<tr><th class='sectionHeader' colspan="2">Manage Programs Explained:</th></tr>
	<tr> <td class='even' valign="top">&nbsp;</td> <td class='odd' valign="top">
	The Manage Programs section is where you add, modify, and delete programs which will be displayed for the end user in the Program Schedule.
	</td> </tr>
	
	<tr> <td class='even' valign="top">1)</td> <td class='odd' valign="top">
	<b>Manage Programs >> Add Programs</b>
	<p>Here you can add a new program.  You will, at the very minimum, need to enter a Program title, start AND end time, and choose the days the program airs. If you have set a start time for the program schedule under the Configuration section, you should give your first row of programs this start time as well.  It is a good idea to check your entries as the end user will see them in the weekly view quite frequently as you are entering programs.
	<br /><br />You will need to be dilligent when entering programs in order to make sure they have accurate start and end times and that the programs are assigned to the appropriate days of the week.  If there are overlapping program times, the grid appearance will most likely be adversly affected.  Also, the end time of each program should be set to the start time of the next program so there are no empty spaces in the program schedule, assuming stations do not intend on having dead air.</p>
	</td> </tr>
	
	<tr> <td class='even' valign="top">2)</td> <td class='odd' valign="top">
	<b>Manage Programs >> Edit Programs</b>
	<p>The "Edit Programs" section will allow you to make changes to program entries.  The important thing here is that you make sure to only have consecutive days selected when updating programs.  You should make a new entry for non-consecutive days in order to avoid display problems in the weekly view.   When entering a new program, non consecutive days are automaticly split into separate program entries.</p>
	</td> </tr>

	
	<tr> <td class='even' valign="top">3)</td> <td class='odd' valign="top">
	<b>Manage Programs >> Delete Programs</b>
	<p>Here you can delete existing Programs.  In the weekly view, if you delete programs on earlier days of the week, programs to the right or later in the week will slide over to left to fill in that spot.  It will be important to fill that spot again with a program that takes up the same amount of time on the same days in order to avoid shuffling other programs to correct the display of the program schedule.</p>
	</td> </tr>

			
</table>
 <?PHP
 }

?>
